' next methods outputs the SELECT tag and all the attributes
' defined previously
output.RenderBeginTag("select")
' now we can add the individual <option> tags
Dim index As Integer
For index = 0 To items.Length - 1
' Add the Value attribute.
output.AddAttribute("value", index.ToString)
' If this is the selected element, add a "selected" attributes
If index > 0 AndAlso index = SelectedIndex Then
output.AddAttribute("selected", "selected")
End If
' Output the <option> tag (and all the attributes set previously)
output.RenderBeginTag("option")
output.Write(items(index))
output.RenderEndTag()
Next
' close the </select> tag.
output.RenderEndTag()
End Sub
' this method is invoked when a postback on the parent form occurs
Public Function LoadPostData(ByVal postDataKey As String, ByVal postCollection As System.Collections.Specialized.NameValueCollection) As Boolean Implements System.Web.UI.IPostBackDataHandler.LoadPostData
' The post value is equal to the index of the selected element.
Dim newSelectedIndex As Integer = CInt(postCollection(postDataKey))
If SelectedIndex <> newSelectedIndex Then
' if the new value is different, store in the property.
SelectedIndex = newSelectedIndex
' Tell ASP.NET to call the RaisePostDataChangedEvent method.
Return True
End If
End Function
' this method is invoked when all the other controls have processed
' their LoadPostData method, and only if the LoadPostData method
' for this ComboBoxEx control returned True.
Public Sub RaisePostDataChangedEvent() Implements System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent
' raise an event in the parent form
OnSelectedIndexChanged(EventArgs.Empty)
End Sub
' inherited controls can override this method to control if and when
' they raise the SelectedIndexChanged event in their clients
Protected Overridable Sub OnSelectedIndexChanged(ByVal e As EventArgs)
RaiseEvent SelectedIndexChanged(Me, e)
End Sub
' another public event
Public Event Click As EventHandler
' this method is invoked if this control caused a postback
Public Sub RaisePostBackEvent(ByVal eventArgument As String) Implements System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
OnClick(EventArgs.Empty)
End Sub
' inherited controls can override this method to control if and when
' they raise the Click event in their clients
Protected Overridable Sub OnClick(ByVal e As EventArgs)